﻿//======================================================================
//  日志记录器
//====================================================================== 

using System;
using System.Collections.Generic;
using System.Text;
using log4net;

namespace Common
{
    /// <summary>
    /// 日志记录器
    /// </summary>
    public sealed class Logger
    {
        private static ILog m_log;
        public static string Applog_All = "Applog.All"; //默认的日志
        
        /// <summary>
        /// 短信发送日志
        /// </summary>
        public static string Applog_SMSSEND = "Applog.SMSSendLog";
        /// <summary>
        /// 写日志(使用log4net组件)
        /// </summary>
        /// <param name="content"></param>
        public static void WriteLog(string content)
        {
            LogManager.GetLogger(Applog_All).Info(content);
        }

        /// <summary>
        /// 写日志(使用log4net组件)
        /// </summary>
        /// <param name="content"></param>
        /// <param name="ex"></param>
        public static void WriteLog(string content, Exception ex)
        {
            LogManager.GetLogger(Applog_All).Info(content, ex);
        }

        /// <summary>
        /// 保存日志-可设置存的文件(使用log4net组件)
        /// </summary>
        /// <param name="message">日志信息</param>
        /// <param name="messageType">日志类型</param>
        /// <param name="loggerName">Logger名称 可以为空记录到默认日志里</param>
        public static void WriteLog(string content, string loggerName)
        {
            m_log = LogManager.GetLogger(loggerName);
            Logger.m_log.Info(content);
        }

        /// <summary>
        /// 保存日志-可设置存的文件(使用log4net组件)
        /// </summary>
        /// <param name="message">日志信息</param>
        /// <param name="ex">异常信息</param>
        /// <param name="loggerName">Logger名称 可以为空记录到默认日志里</param>
        public static void WriteLog(string content, Exception ex, string loggerName)
        {
            m_log = LogManager.GetLogger(loggerName);

            Logger.m_log.Info(content, ex);
        }
    }
}
